package com.mijie.homi.service.user;

import java.util.List;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mijie.homi.common.constant.CategoryCode;
import com.mijie.homi.common.constant.TypeCode;
import com.mijie.homi.common.domain.user.Friend;
import com.mijie.homi.common.domain.user.User;
import com.mijie.homi.common.protocol.HomiProtocol;
import com.mijie.homi.common.util.HomiUtil;
import com.mijie.homi.dao.user.FriendDao;
import com.mijie.homi.service.notify.NotifyUserAgent;
import com.mijie.homi.util.ServerHelper;

@Service
public class FriendService {

	@Autowired
	private FriendDao dao;
	@Autowired
	private NotifyUserAgent notifyUserAgent;
	@Autowired
	private UserService userService;
	
	public boolean isFriend(int userId,int friendId){
		return dao.isFriend(userId, friendId);
	}
	
	public List<Friend> listFriend(int userId){
		return dao.listFriend(userId);
	}
	
	public int deleteFriend(int userId,int friendId){
		return dao.deleteFriend(userId, friendId);
	}
	
	private int addFriend(int userId,int friendId){
		return  dao.addFriend(userId, friendId);
	}
	
	public void requestToAddFriend(int requester,int receiver){
		notifyUserAgent.sendNotifyForRequestToAddFriend(requester, receiver);
	}
	
	public void rejectToAddFriend(int userId,int requester){
		notifyUserAgent.sendNotifyForRejectAddFriend(userId, requester);
	}
	
	public void acceptToAddFriend(int userId,int requester){
		notifyUserAgent.sendNotifyForAcceptToAddFriend(userId, requester);
		//添加好友为双向关系
		addFriend(requester,userId);
		addFriend(userId,requester);
	}
	
	public List<Integer> listFriendId(int userId){
		return dao.listFriendId(userId);
	}
	
	public List<Integer> listBeFriendWithMeUser(int userId){
		return dao.listBeFriendWithMeUser(userId);
	}
}
